package com.bbc.base.page;

/**
 * 2012-11-23
 * @author hanshaofeng
 *
 * @param <T>
 */
public class MysqlPaginatedArrayList<T> extends AbstractPaginatedList<T> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 默认构造方法
	 */
	public MysqlPaginatedArrayList() {
		super();
	}

	/**
	 * 带当前页和页大小的构造方法
	 * @param index 当前页
	 * @param pageSize 页大小
	 */
	public MysqlPaginatedArrayList(int index, int pageSize) {
		super(index, pageSize);
	}

	@Override
	protected void repaginate() {
		if (pageSize < 1) { 
			pageSize = PAGESIZE_DEFAULT;
		}
		if (index < 1) {
			index = 1;//恢复到第一页
		}
		if (totalItem > 0) {
			totalPage = totalItem / pageSize + (totalItem % pageSize > 0 ? 1 : 0);
			if (index > totalPage) {
				index = totalPage; //最大页
			}

			endRow = index * pageSize;
			startRow = endRow - pageSize;
			endRow = pageSize;

			if (endRow > totalItem) {
				endRow = totalItem;
			}
		}
	}

}
